/* GUI CONVERTED from rcsoisg.p (converter v1.75) Tue Apr 10 12:05:48 2001 */
/* rcsoisg.p - Validate against available inventory                           */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                        */
/* All rights reserved worldwide.  This is an unpublished work.               */
/* $Revision: 1.9.1.11 $                                                       */
/*V8:ConvertMode=Maintenance                                                  */
/* REVISION: 7.3          CREATED: 01/20/95           BY: rxm *G0CX*          */
/* REVISION: 7.3    LAST MODIFIED: 08/03/95           BY: vrn *G0TJ*          */
/* REVISION: 7.3    LAST MODIFIED: 10/17/95           BY: jym *F0TC*          */
/* REVISION: 7.3    LAST MODIFIED: 01/02/96           BY: ais *G1HQ*          */
/* REVISION: 8.5    LAST MODIFIED: 02/13/96           BY: tjs *J0B1*          */
/* REVISION: 8.5    LAST MODIFIED: 04/01/96           BY: vrn *G1RW*          */
/* REVISION: 8.5    LAST MODIFIED: 09/04/96     BY: *G2CM* Ajit Deodhar       */
/* REVISION: 8.6    LAST MODIFIED: 10/09/96     BY: *K003* forrest mori       */
/* REVISION: 8.6    LAST MODIFIED: 09/17/97     BY: *G2PK* Seema Varma        */
/* REVISION: 8.6    LAST MODIFIED: 12/13/97     BY: *J20Q* Aruna Patil        */
/* REVISION: 8.6    LAST MODIFIED: 02/10/98     BY: *K1G4* Jim Williams       */
/* REVISION: 8.6    LAST MODIFIED: 05/20/98     BY: *K1Q4* Alfred Tan         */
/* REVISION: 8.6    LAST MODIFIED: 09/15/98     BY: *K1X2* Manish K.          */
/* REVISION: 8.6    LAST MODIFIED: 02/17/99     BY: *J3B9* Narender           */
/* REVISION: 9.0    LAST MODIFIED: 03/29/99     BY: *J3BM* Reetu Kapoor       */
/* REVISION: 9.0    LAST MODIFIED: 02/09/00     BY: *L0R7* Reetu Kapoor       */
/* REVISION: 9.1    LAST MODIFIED: 09/05/00     BY: *N0RF* Mark Brown         */
/* REVISION: 9.1    LAST MODIFIED: 10/04/00     BY: *L0TS* Mansih K.          */
/* REVISION: 9.1    LAST MODIFIED: 11/21/00     BY: *M0WV* Sandeep P.         */
/* REVISION: 9.1    LAST MODIFIED: 01/22/01     BY: *M10D* Rajesh Thomas      */
/* REVISION: 9.1    LAST MODIFIED: 09/23/00     BY: *N0WD* BalbeerS Rajput    */
/* Old ECO marker removed, but no ECO header exists *F0PN*                    */
/* $Revision: 1.9.1.11 $   BY: Jean Miller       DATE: 03/22/01  ECO: *P008*   */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

/* VALIDATES THAT THERE IS ADEQUATE INVENTORY AVAILABLE TO SHIP ALL
 * LINES WITH SAME SITE, LOC & PART IF OVER-ISSUE NOT ALLOWED.
 * PER BILL GATES, ALL LINES MUST SHIP OR NONE SHIP */

{mfdeclre.i}
{cxcustom.i "RCSOISG.P"}

define shared variable so_db like global_db.
define shared variable ship_db like global_db.
define shared variable change_db like mfc_logical.
define shared variable rejected like mfc_logical no-undo.
define shared variable confirm_mode like mfc_logical no-undo.

define        variable accum_ship_qty as decimal.
define        variable err-flag as integer.
define        variable umconv like sod_um_conv no-undo.
define        variable um like sod_um no-undo.

{&RCSOISG-P-TAG1}

{rcwabsdf.i}

assign
   rejected = no.

run p_cont_inventory_check.
if rejected then
   leave.

for each work_abs_mstr no-lock where abs_order > "",
    each sod_det exclusive-lock where
         sod_nbr = abs_order
     and sod_line = integer(abs_line)
     and sod_type = ""
break by abs_site by abs_loc by abs_item by abs_lotser by abs_ref:

   {&RCSOISG-P-TAG2}

   /* SWITCH DATABASES TO FIND ALLOCATIONS IF NECESSARY */
   for first si_mstr
   fields (si_db si_site)
   where si_site = abs_site no-lock:
   end. /* FOR FIRST SI_MSTR */

   if available si_mstr then
      ship_db = si_db.
   else do:
      /* SITE DOES NOT EXIST */
      {pxmsg.i &MSGNUM=708 &ERRORLEVEL=4 &MSGARG1=abs_site}
      pause.
      rejected = yes.
      leave.
   end.

   change_db = (ship_db <> global_db).

   if change_db then do:
      so_db = global_db.
      {gprun.i ""gpalias3.p"" "(ship_db, output err-flag)"}
/*GUI*/ if global-beam-me-up then undo, leave.

      if err-flag = 2 or err-flag = 3  then do:
         /* Database not connected */
         {pxmsg.i &MSGNUM=2510 &ERRORLEVEL=4 &MSGARG1=ship_db}
         pause.
         rejected = yes.
         leave.
      end.
   end.

   if first-of(abs_ref) then
      accum_ship_qty = 0.

   if first-of(abs_item) then do:

      /* SET UM AND CONVERSION FROM pt_mstr FOR KIT COMPONENTS */
      if abs_item <> sod_part and sod_type = "" then
      for first pt_mstr
      fields (pt_part pt_um)
      where pt_part = abs_item no-lock:
         assign
            um = pt_um
            umconv = 1.
      end. /* FOR FIRST PT_MSTR */

      /* CONVERT SHIP UM TO INVENTORY UM FOR INVENTORY VALIDATION */
      if abs_item = sod_part then
         assign
            um = abs__qad02
            umconv = decimal(abs__qad03).

   end.

   if sod_type = "" then
      if confirm_mode = yes then
         accum_ship_qty = accum_ship_qty + abs_qty - abs_ship_qty.
      else
         accum_ship_qty = accum_ship_qty + (abs_qty * -1).

   /* THE INVENTORY CHECK FOR ATO ITEMS IS DONE IN RCSOIS1A.P */
   /* AFTER THE CALL TO RCSOISJ.P                             */
   /* ADDED CHECK ON abs_item TO ENSURE KIT COMPONENTS ARE EXCLUDED */
   /* WHEN SO DETAIL LINE HAS CONFIGURED PARENT ITEM.               */
   if  abs_id begins "I"
      and abs_item = sod_part
   then do:

      if not (can-find (first abs_mstr
         where abs_mstr.abs_shipfrom = work_abs_mstr.abs_shipfrom and
               abs_mstr.abs_par_id = work_abs_mstr.abs_id ) ) and
         not (can-find (first pt_mstr
         where pt_part     = work_abs_mstr.abs_item
           and pt_pm_code  = "C"
          and pt_cfg_type = "1"))
      then do:

         {&RCSOISG-P-TAG3}

         {gprun.i ""icedit2.p""
            "(input ""ISS-SO"",
              input abs_site,
              input abs_loc,
              input abs_item,
              input abs_lotser,
              input abs_ref,
              input accum_ship_qty * umconv,
              input um,
              input """",
              input """",
              output rejected)"}
/*GUI*/ if global-beam-me-up then undo, leave.


         {&RCSOISG-P-TAG4}

      end. /* IF NOT CAN_FIND */

   end. /* IF ABS_ID */

   /* RETURN TO SALES ORDER DATABASE */
   if change_db then do:
      {gprun.i ""gpalias3.p"" "(so_db, output err-flag)" }
/*GUI*/ if global-beam-me-up then undo, leave.

      if err-flag = 2 or err-flag = 3 then do:
         /* Database not connected */
         {pxmsg.i &MSGNUM=2510 &ERRORLEVEL=4 &MSGARG1=so_db}
         pause.
      end.
   end.

   if rejected then do:
      /* Insufficient Inventory to ship */
      {pxmsg.i &MSGNUM=161 &ERRORLEVEL=3 &MSGARG1=abs_item}
      pause.
      leave.
   end.
end.

PROCEDURE p_cont_inventory_check:
/*--------------------------------------------------------------------
   Purpose:     Check Sufficient inventory to ship for Containers
   Parameters:
   Notes:
----------------------------------------------------------------------*/
   for each work_abs_mstr
      where abs_order             = "" and
            abs_line              = "" and
            substring(abs_id,1,1) = "c"
   break by abs_site
         by abs_loc
         by abs_item
         by abs_lotser
         by abs_ref:

      /* SWITCH DATABASES TO FIND ALLOCATIONS IF NECESSARY */
      for first si_mstr
      fields (si_db si_site)
      where si_site = abs_site no-lock:
      end. /* FOR FIRST SI_MSTR */

      if available si_mstr then
         ship_db = si_db.
      else do:
         /* SITE DOES NOT EXIST */
         {pxmsg.i &MSGNUM=708 &ERRORLEVEL=4 &MSGARG1=abs_site}
         pause.
         rejected = yes.
         leave.
      end. /* IF NOT AVAILABLE SI_MSTR */

      change_db = (ship_db <> global_db).

      if change_db then do:
         so_db = global_db.
         {gprun.i ""gpalias3.p"" "(ship_db, output err-flag)"}
/*GUI*/ if global-beam-me-up then undo, leave.

         if err-flag = 2 or err-flag = 3  then do:
            /* Database not connected */
            {pxmsg.i &MSGNUM=2510 &ERRORLEVEL=4 &MSGARG1=ship_db}
            pause.
            rejected = yes.
            leave.
         end. /* IF ERR-FLAG = 2 ... */
      end. /* IF CHANGE_DB */

      if first-of(abs_ref) then
         accum_ship_qty = 0.

      if confirm_mode then
         accum_ship_qty = accum_ship_qty + abs_qty - abs_ship_qty.
      else
         accum_ship_qty = -1 * (accum_ship_qty + abs_qty).

      {gprun.i ""icedit2.p""
         "(input ""ISS-UNP"",
           input abs_site,
           input abs_loc,
           input abs_item,
           input abs_lotser,
           input abs_ref,
           input accum_ship_qty,
           input um,
           input """",
           input """",
           output rejected)"}
/*GUI*/ if global-beam-me-up then undo, leave.


      /* RETURN TO SALES ORDER DATABASE */
      if change_db then do:
         {gprun.i ""gpalias3.p"" "(so_db, output err-flag)" }
/*GUI*/ if global-beam-me-up then undo, leave.

         if err-flag = 2 or err-flag = 3 then do:
            /* Database not connected */
            {pxmsg.i &MSGNUM=2510 &ERRORLEVEL=4 &MSGARG1=so_db}
            pause.
         end. /* IF ERR-FLAG = 2 ...*/
      end. /* IF CHANGE_DB */

      if rejected then do:
         /* INSUFFICIENT INVENTORY TO SHIP */
         {pxmsg.i &MSGNUM=161 &ERRORLEVEL=3 &MSGARG1=abs_item}
         pause.
         leave.
      end. /* IF REJECTED */

   end. /* FOR EACH WORK_ABS_MSTR */

END PROCEDURE. /* PROCEDURE P_CONT_INVENTORY_CHECK */
